// component/inpbar/inpbar.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    statusBarHeight: {
      type: String,
    },
    api_host: {
      type: String
    },
    param: {
      type: Object
    },
    template: {
      type: Array
    },
    wxapp_img: {
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    systemInfo: getApp().core.getSystemInfoSync(),
    top: 0,
    is_show_btn: false,
    shop_info_param: null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    px2rpx: function (px) {
      const screenWidth = this.data.systemInfo.screenWidth
      return (750 / screenWidth) * px
    },
    onClick: function () {
      wx.navigateTo({
        url: '/pages/search/search',
      })
    },
    onClickUrl: function (e) {
      var o = e.currentTarget.dataset.open_type;
      if ("tel" == o) {
        var n = e.currentTarget.dataset.tel;
        getApp().core.makePhoneCall({
          phoneNumber: n
        });
      } else {
        var url = e.currentTarget.dataset.url;
        if (url.indexOf('pages/index/index') >= 0 ||
        url.indexOf('pages/cat/cat') >= 0 ||
        url.indexOf('pages/cart/cart') >= 0 ||
        url.indexOf('pages/posts/index') >= 0 ||
        url.indexOf('pages/user/user') >= 0
        ) {
            wx.switchTab({ url })
        } else {
          wx.navigateTo({
            url: url,
          })
        }
      }
      return !1;
    }
  },
  lifetimes: {
    attached: function () {
      var is_show_btn = false
      var shop_info_param = null
      if (this.data.template[0].type == 'shop_info') {
        is_show_btn = true
        shop_info_param = this.data.template[0].param
      }
      var statusBarHeight = this.px2rpx(this.data.systemInfo.statusBarHeight)
      this.setData({
        shop_info_param: shop_info_param,
        is_show_btn: is_show_btn,
        top: statusBarHeight + 86
      })
    }
  }
})